package br.com.ilha.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import br.com.ilha.bo.EstadoBo;
import br.com.ilha.bo.MunicipioBO;

public class BancoAction {

	@Action(value = "geraBanco", results = {
			@Result(name = "ok", location = "populaBanco", type = "redirectAction")
	})
	public String geraBanco() {

		AnnotationConfiguration ac = new AnnotationConfiguration();
		ac.configure();

		SchemaExport se = new SchemaExport(ac);
		se.create(true, true);

		return "ok";

	}

	@Action(value = "populaBanco", results = {
			@Result(name = "ok", location = "/teste.html")
	})
	public String populaBanco() {

		System.out.println("");
		System.out.println("POPULANDO REGISTROS");

		EstadoBo estadoBo = new EstadoBo();
		estadoBo.populaEstados();
		
		MunicipioBO municipioBo = new MunicipioBO();
		municipioBo.populaMunicipios();

		return "ok";

	}

}
